#!/usr/bin/expect

set ipaddr139 "172.16.67.139"
set ipaddr145 "172.16.67.145"

set passwd "c8kdu3new"

spawn ssh-keygen -t dsa

expect {
  "*.ssh/id_dsa)" {send "\n";exp_continue}
  "*for no passphrase" {send "\n";exp_continue}
  "*again" {send "\n"}
}
expect eof

spawn ssh-copy-id -i /root/.ssh/id_dsa.pub root@$ipaddr145
expect {
"*yes/no)*" {send "yes\n";exp_continue}
"*password:*" {send "$passwd\n"}
}
expect eof

spawn ssh-copy-id -i /root/.ssh/id_dsa.pub root@$ipaddr139
expect {
"*yes/no)*" {send "yes\n";exp_continue}
"*password:*" {send "$passwd\n"}
}
expect eof